//
//  WZGProtocolListViewModel.m
//  ZCJZ
//
//  Created by sujeking on 2019/12/23.
//  Copyright © 2019 jeking. All rights reserved.
//

#import "WZGProtocolListViewModel.h"
#import "ZCWebVC.h"
@implementation WZGProtocolListViewModel

+ (void)loadProtolcolContentVCWithDict:(NSDictionary *)dict {
    UIViewController *topvc = [self visibleViewController];
    ZCWebVC *vc = [[ZCWebVC alloc] init];
    vc.navTitle = [dict valueForKey:@"protocol_name"];
    vc.htmlstr = [dict valueForKey:@"protocol_content"];
    [topvc.navigationController pushViewController:vc animated:YES];
}

+ (UIViewController *)visibleViewController {
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;;
    return [self getVisibleViewControllerFrom:rootViewController];
}

+ (UIViewController *)getVisibleViewControllerFrom:(UIViewController *) vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self getVisibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self getVisibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];
    } else {
        if (vc.presentedViewController) {
            return [self getVisibleViewControllerFrom:vc.presentedViewController];
        } else {
            return vc;
        }
    }
}



+ (void)netFetchProtocolsWithModuleName:(NSString *)moduleName
                                success:(void (^)(ZCErrorCode status, NSString * msg, id data))success
                                failure:(void (^)(ZCErrorCode status, NSString *msg, NSDictionary * data))failure {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:moduleName forKey:@"position"];
    [SKBaseWebService postRequest:@"/v1/protocol/get-protocol" parameters:parameters progress:nil success:^(ZCErrorCode status, NSString *msg, id data) {
        success(status,msg,data);
    } failure:^(ZCErrorCode status, NSString *msg, NSDictionary *data) {
        failure(status,msg,data);
    }];

}


@end
